<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!--分页-->
<div class="pull-left mb20 ml20 mt5">
	总记录${page.rowCount}条 ${page.pageId}/${page.pageCount}页
</div>
<div class="pull-center c-fenye mb20">
	<span class="fenye-bb">
		<c:choose>
			<c:when test="${not empty page.pageId && page.rowCount != 0}">
			
				<span class="mr20">
					每页记录数：
					<select id="pageSize" name="pager.pageSize">
						<c:forEach var="item" items="${fns:getDictList('page_num')}">
							<option value="${item.dictValue }" <c:if test="${page.pageSize == item.dictValue }">selected</c:if>>${item.dictName }</option>
						</c:forEach>
					</select>
				</span>
				
				<c:choose>
					<c:when test="${page.pageId == 1}">
						<a  class="fanye" href="javaScript:;">上一页</a>
					</c:when>
					<c:otherwise><a  class="fanye" href="javaScript:prePage();">上一页</a></c:otherwise>
				</c:choose>
				<c:choose>
					<c:when test="${page.pageCount<=5}">
						<c:forEach var="i" begin="1" end="${page.pageCount}" varStatus="status">
							<c:if test="${status.index == page.pageId}">
							    <a class="hover" href="javaScript:goPage('${status.index}');">${status.index}</a>
							</c:if>
							<c:if test="${status.index != page.pageId}">
                                <a href="javaScript:goPage('${status.index}');">${status.index}</a>
                            </c:if> 
						</c:forEach>
					</c:when>
					<c:otherwise>
						<c:forEach var="i" begin="${(page.pageCount-page.pageId)<5?(page.pageCount-4):page.pageId}" end="${page.pageCount<(page.pageId+4)?page.pageCount:(page.pageId+4)}" varStatus="status">
						    <c:if test="${status.index == page.pageId}">
                                <a class="hover" href="javaScript:goPage('${status.index}');">${status.index}</a>
                            </c:if>
                            <c:if test="${status.index != page.pageId}">
                                <a href="javaScript:goPage('${status.index}');">${status.index}</a>
                            </c:if>
						</c:forEach>
					</c:otherwise>
				</c:choose>
				<c:choose>
					<c:when test="${page.pageId == page.pageCount}">
						<a  class="fanye" href="javaScript:;">下一页</a>
					</c:when>
					<c:otherwise>
						<a  class="fanye" href="javaScript:nextPage();">下一页</a>
					</c:otherwise>
				</c:choose>
				
				<span class="ml20">
					跳转到
					<input id="toGoPage" class="w30" onkeyup="value=value.replace(/[^(\d)]/g,'')" onafterpaste="value=value.replace(/[^(\d)]/g,'')"/>
					<a class="fanye" href="javaScript:toGoPage();">GO</a>
				</span>
			</c:when>
			<c:otherwise>
				<label>无任何记录</label>
			</c:otherwise>
		</c:choose>
    </span>
</div>
<!--分页 end-->
<input type="hidden" id="pn" name="pager.pageId" value="${page.pageId==null?0:page.pageId }" />
<input type="hidden" id="pageCount" value="${page.pageCount}" >
<script type="text/javascript">
	//到指定的分页页面
	function toGoPage() {
		var toGoPage = $("#toGoPage").val();
		var lastPage=$("#pageCount").val();
		if (toGoPage != null && toGoPage != "" && Number(toGoPage) <= Number(lastPage)) {
			$("#pn").val(toGoPage);
			toPage();
		}
	}
	// 跳转到分页
	function toPage() {
		var showPage = $("#pn").val();
		if(parseInt(showPage)<=0){
			showPage=1;
			$("#pn").val("1");
		}
		if (showPage <= $("#pn").val()) {
			$("#pn").val(showPage);
			$('#fenyeForm').submit(); // 提交表单
			$("#pn").focus();
		}
	}
	function fisrtPage(){
		$("#pn").val("1");
		toPage();
	}
	function lastPage(){
		var lastPage=$("#pageCount").val();
		$("#pn").val(lastPage);
		toPage();
	}
	function goPage(showPage){
		$("#pn").val(showPage);
		toPage();   
	}
	function nextPage(){
		var next=parseInt($("#pn").val())+1;
		$("#pn").val(next);
		toPage();
	}
	function prePage(){
		var pre=parseInt($("#pn").val())-1;
		$("#pn").val(pre);
		toPage();
	}
	$(function(){
		$(document).keypress(function(e) {
			// 回车键事件  
			if (e.which == 13) {
				toGoPage();
			}
		});
		$("#pageSize").change(function(){
			fisrtPage();
		});
	});
</script>

